package com.lp.multi.thread.example05;

import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @author: lp
 * @create: 2021-06-22 16:12
 * @description: 使用JUC集合达到并发安全
 */
public class JucSafeList {
    public static void main(String[] args) throws InterruptedException {
        CopyOnWriteArrayList<String> strings = new CopyOnWriteArrayList<String>();
        for (int i = 0; i < 10000; i++) {
            new Thread(()->{
                strings.add(Thread.currentThread().getName());
            }).start();
        }
        Thread.sleep(3000);
        System.out.println("strings.size() = " + strings.size());
    }
}
